package batch.retry.listener;

import org.springframework.batch.retry.RetryCallback;
import org.springframework.batch.retry.RetryContext;
import org.springframework.batch.retry.RetryListener;

/**
 * Simple Repeat Listener listening on retry operations.
 * 
 * @author Andrei.Chirila
 */
public class SimpleRetryListener implements RetryListener {

	/**
	 * Called after the final attempt (successful or not).
	 */
	@Override
	public <T> void close(RetryContext retryContext, RetryCallback<T> retryCallback,
			Throwable throwable) {
		System.out.println("No more retry attempts...");
	}

	/**
	 * Called after every unsuccessful attempt at a retry.
	 */
	@Override
	public <T> void onError(RetryContext retryContext, RetryCallback<T> retryCallback,
			Throwable throwable) {
		System.out.println("Unsuccessful call...");
	}

	/**
	 * Called before the first attempt in a retry.
	 */
	@Override
	public <T> boolean open(RetryContext retryContext, RetryCallback<T> retryCallback) {
		System.out.println("Attempting call...");
		return true;
	}

}
